//
//  ZZCJoinController.m
//  ZZC-Finance
//
//  Created by mac on 2017/5/21.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "ZZCJoinController.h"
#import "ZZCLawController.h"
#import "ZZCEvaluateController.h"
#import "ZZCAgentController.h"
#import "ZZCEvaluateController.h"
#import "ZZCEvaluateStatusController.h"
#import "ZZCAgentController.h"
#import "ZZCAgentStatusController.h"
#import "IQKeyboardManager.h"

#import "ZZCLawStatusController.h"

@interface ZZCJoinController ()
{
    NSInteger is_company;
}
@property (copy, nonatomic) NSString *stateType;

@end

@implementation ZZCJoinController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"代理合作";
    IQKeyboardManager *iq = [IQKeyboardManager sharedManager];
    iq.enableAutoToolbar = YES;
    is_company = [[NSUserDefaults standardUserDefaults] integerForKey:@"IS_COMPANY"];
    NSLog(@"_______%ld",(long)is_company);
}

//法律专家
- (IBAction)lawClick {
    if (is_company == 1) {
        NSLog(@"为企业帐号无法申请代理商");
        [SVProgressHUD showInfoWithStatus:@"企业帐号无法申请代理商"];
    } else {
        self.stateType = @"1";
        [self checkState];
    }
}
//评估专家
- (IBAction)evaluateClick {
    if (is_company == 1) {
        NSLog(@"为企业帐号无法申请代理商");
        [SVProgressHUD showInfoWithStatus:@"企业帐号无法申请代理商"];
    } else {
        self.stateType = @"2";
        [self checkState];
    }
}
//代理商
- (IBAction)agentClick {
    if (is_company == 0) {
        NSLog(@"为个人帐号无法申请代理商");
        [SVProgressHUD showInfoWithStatus:@"个人帐号无法申请代理商"];
    } else {
        self.stateType = @"3";
        [self checkState];
    }

}


/** checkStatue */
- (void)checkState {
    ZZCLog(@"判断状态");
    NSDictionary *token = ZZCNSUserDefaults(@"token");
    
    NSDate *currentDate = [NSDate date];
    NSString *timeStr = [NSString stringWithFormat:@"%ld",(long)[currentDate timeIntervalSince1970]];
    NSDictionary *dict = @{
                           @"token":token,
                           @"type":_stateType,
                           };
    
    NSString *sign = [ZZCRequest getSignWithDict:dict];
    sign = [NSString md5:[sign lowercaseString]];
    NSDictionary *param = @{
                            @"timestamp":timeStr,
                            @"sign":sign,
                            @"token":token,
                            @"type":_stateType
                            };
    NSLog(@"%@",param);
    [[ZZCRequest sharedNetworkTools] POST:ZZCURL_API_STATUS parameters:param finished:^(id  _Nullable responseObject, NSError * _Nullable error) {
        NSInteger code = [responseObject[@"code"] integerValue];
        if (!error) {
            NSLog(@"（（（（（（（（（）））））））））%@",responseObject);
            //律师
            if ([_stateType isEqualToString:@"1"]) {
                if (code == 200) {
                    ZZCLawStatusController *lawStaus = [ZZCLawStatusController new];
                    [self.navigationController pushViewController:lawStaus animated:YES];
                } else {
                    ZZCLawController *law = [ZZCLawController new];
                    [self.navigationController pushViewController:law animated:YES];
                }
            }
            //评估
            if ([_stateType isEqualToString:@"2"]) {
                if (code == 200) {
                    ZZCEvaluateStatusController *evaStatus = [ZZCEvaluateStatusController new];
                    [self.navigationController pushViewController:evaStatus animated:YES];
                } else {
                    ZZCEvaluateController *eva = [ZZCEvaluateController new];
                    [self.navigationController pushViewController:eva animated:YES];
                }
            }
            //代理商
            if ([_stateType isEqualToString:@"3"]) {
                if (code == 200) {
                    ZZCAgentStatusController *ageStatu = [ZZCAgentStatusController new];
                    [self.navigationController pushViewController:ageStatu animated:YES];
                } else {
                    ZZCAgentController *age = [ZZCAgentController new];
                    [self.navigationController pushViewController:age animated:YES];
                }
            }
            
            
        } else {
            
            NSLog(@"%@",error);
        
        }
    }];
    
}
@end
